/**
 * WebView
 */
import React, {Component} from 'react';
import {
    StyleSheet,
    Text,
    View,
    Platform,
    TouchableOpacity,
    Image,
    WebView,
    BackAndroid
} from 'react-native';
import Icon from 'react-native-vector-icons/FontAwesome';
let icon_camera_back_normal = require('../../img/icon_camera_back_normal.png');
let icon_mine_setting = require('../../img/icon_mine_setting.png');
export default class MyWebView extends Component {

    constructor(props) {
        super(props);
        this.state = {
            url: ''
        };
        this.back=this.back.bind(this)
    }

    componentDidMount() {
        // this.props.tabBar.hide();
        const { params } = this.props.navigation.state;
        let url=params.url;
        this.setState({
            url: url + '?uuid=5C7B6342814C7B496D836A69C872202B5DE8DB689A2D777DFC717E10FC0B4271&utm_term=6.6&utm_source=AppStore&utm_content=5C7B6342814C7B496D836A69C872202B5DE8DB689A2D777DFC717E10FC0B4271&version_name=6.6&userid=160495643&utm_medium=iphone&lat=23.134709&utm_campaign=AgroupBgroupD100Ghomepage_shoppingmall_detailH0&token=b81UqRVf6pTL4UPLLBU7onkvyQoAAAAAAQIAACQVmmlv_Qf_xR-hBJVMtIlq7nYgStcvRiK_CHFmZ5Gf70DR47KP2VSP1Fu5Fc1ndA&lng=113.373890&f=iphone&ci=20&msid=0FA91DDF-BF5B-4DA2-B05D-FA2032F30C6C2016-04-04-08-38594'
        });

    }
    componentWillMount () {
        if (Platform.OS === 'android') {
            BackAndroid.addEventListener('hardwareBackPress', this.back);
        }
    }

    componentWillUnmount(){
        if (Platform.OS === 'android') {
            BackAndroid.removeEventListener('hardwareBackPress', this.back);
        }
    }
    back(){
        this.props.navigation.goBack();
        return true;
    }

    render() {
        return (
            <View style={styles.container}>
                <WebView
                    automaticallyAdjustContentInsets={true}
                    source={{uri: this.state.url}}
                    javaScriptEnabled={true}
                    domStorageEnabled={true}
                    decelerationRate="normal"
                    startInLoadingState={true}
                />
            </View>
        );
    }

    static navigationOptions = ({navigation}) => ({
        title: navigation.state.params.title,
    });
}
MyWebView.propTypes={
    title:React.PropTypes.string
};
MyWebView.defaultProps={
    title:''
};

const styles = StyleSheet.create({
    container: {
        flex: 1
    },
    leftViewStyle: {
        // 绝对定位
        // position: 'absolute',
        // left: 10,
        // top: Platform.OS == 'ios' ? 24 : 10,
        flexDirection:"row",
        alignItems:'center',
        justifyContent:'center'
    },
    navOutViewStyle: {
        height: Platform.OS == 'ios' ? 64 : 44,
        backgroundColor: 'rgba(255,96,0,1.0)',

        // 设置主轴的方向
        flexDirection: 'row',
        // 垂直居中 ---> 设置侧轴的对齐方式
        alignItems: 'center',
        // 主轴方向居中
        justifyContent: 'space-between'
    },
});